import 'package:flutter/material.dart';

class Test003 extends StatefulWidget {
  const Test003({Key? key}) : super(key: key);

  @override
  State<Test003> createState() => _Test003State();
}

class _Test003State extends State<Test003> {
  var run = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("动画"),
      ),
      body: TweenAnimationBuilder(
        duration: const Duration(seconds: 2),
        tween: Tween(begin: 0.0, end: run ? 1.0 : 0.5),
        builder: (BuildContext context, double value, Widget? child) {
          return Opacity(
            opacity: value,
            child: Column(
              children: [
                Container(
                  width: 200,
                  height: 200,
                  color: Colors.blue,
                  child: Center(
                    child: Transform.scale(
                      scale: value,
                      child: const Text(
                        "Hello",
                        style: TextStyle(fontSize: (25)),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 200,
                  height: 200,
                  color: Colors.red,
                  child: Center(
                    child: Transform.rotate(
                      angle: value * 50,
                      child: const Text(
                        "Hello",
                        style: TextStyle(fontSize: (25)),
                      ),
                    ),
                  ),
                ),
                Container(
                  width: 200,
                  height: 200,
                  color: Colors.yellow,
                  child: Center(
                    child: Transform.translate(
                      offset: Offset(value * 5, value * 50),
                      child: const Text(
                        "Hello",
                        style: TextStyle(fontSize: (25)),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            run = !run;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
